package com.rxt.thermopro.bean

import android.os.Parcel
import android.os.Parcelable
import com.rxt.thermopro.R


data class ProfileBean(
    var name: String,
    var profileValue: String,
    var itemValues: List<ProfileItem>,
    var highTemperatureNum: String = "",
    var lowTemperatureNum: String = "",
    var singleTemp: Boolean = true,
    var checked: Boolean = false,
    var iconRes: Int = R.drawable.icon,
    var id: String = "-1",
    var highValueC: String = "",
    var lowValueC: String = "",
    var highValueF: String = "",
    var lowValueF: String = "",
    var isCustomAdd: Boolean = false
) : Parcelable {
    constructor(parcel: Parcel) : this(
        parcel.readString() ?: "",
        parcel.readString() ?: "",
        parcel.createTypedArrayList(ProfileItem) ?: arrayListOf(),
        parcel.readString() ?: "",
        parcel.readString() ?: "",
        parcel.readByte() != 0.toByte(),
        parcel.readByte() != 0.toByte(),
        parcel.readInt(),
        parcel.readString() ?: "",
        parcel.readString() ?: "",
        parcel.readString() ?: "",
        parcel.readString() ?: "",
        parcel.readString() ?: "",
        parcel.readByte() != 0.toByte()
    ) {
    }

    override fun writeToParcel(parcel: Parcel, flags: Int) {
        parcel.writeString(name)
        parcel.writeString(profileValue)
        parcel.writeTypedList(itemValues)
        parcel.writeString(highTemperatureNum)
        parcel.writeString(lowTemperatureNum)
        parcel.writeByte(if (singleTemp) 1 else 0)
        parcel.writeByte(if (checked) 1 else 0)
        parcel.writeInt(iconRes)
        parcel.writeString(id)
        parcel.writeString(highValueC)
        parcel.writeString(lowValueC)
        parcel.writeString(highValueF)
        parcel.writeString(lowValueF)
        parcel.writeByte(if (isCustomAdd) 1 else 0)
    }

    override fun describeContents(): Int {
        return 0
    }

    companion object CREATOR : Parcelable.Creator<ProfileBean> {
        override fun createFromParcel(parcel: Parcel): ProfileBean {
            return ProfileBean(parcel)
        }

        override fun newArray(size: Int): Array<ProfileBean?> {
            return arrayOfNulls(size)
        }
    }

}

data class ProfileItem(
    var itemName: String,
    var itemValue: String,
    var checked: Boolean = false,
    var itemValueC: String = "",
    var itemValueF: String = "",
) : Parcelable {
    constructor(parcel: Parcel) : this(
        parcel.readString() ?: "",
        parcel.readString() ?: "",
        parcel.readByte() != 0.toByte(),
        parcel.readString() ?: "",
        parcel.readString() ?: ""
    ) {
    }

    override fun writeToParcel(parcel: Parcel, flags: Int) {
        parcel.writeString(itemName)
        parcel.writeString(itemValue)
        parcel.writeByte(if (checked) 1 else 0)
        parcel.writeString(itemValueC)
        parcel.writeString(itemValueF)
    }

    override fun describeContents(): Int {
        return 0
    }

    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (javaClass != other?.javaClass) return false

        other as ProfileItem

        if (itemName != other.itemName) return false
        if (itemValue != other.itemValue) return false
        if (checked != other.checked) return false
        if (itemValueC != other.itemValueC) return false
        if (itemValueF != other.itemValueF) return false

        return true
    }

    override fun hashCode(): Int {
        var result = itemName.hashCode()
        result = 31 * result + itemValue.hashCode()
        result = 31 * result + checked.hashCode()
        result = 31 * result + itemValueC.hashCode()
        result = 31 * result + itemValueF.hashCode()
        return result
    }

    companion object CREATOR : Parcelable.Creator<ProfileItem> {
        override fun createFromParcel(parcel: Parcel): ProfileItem {
            return ProfileItem(parcel)
        }

        override fun newArray(size: Int): Array<ProfileItem?> {
            return arrayOfNulls(size)
        }
    }


}